package com.lsy.controller.back;

import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.SessionAttributes;
import org.springframework.web.servlet.ModelAndView;

import com.lsy.entity.Admin;

@Controller
@RequestMapping("/back")
@SessionAttributes("admin")
public class IndexBackController {

	private final static String CODE = "admin";
	private final static String PASSWORD = "123";

	@RequestMapping("/admin")
	public ModelAndView index() {
		ModelAndView view = new ModelAndView("/BackEnd/admin");
		return view;
	}

	@RequestMapping("/login")
	public ModelAndView login(String code, String password, Model model) {
		if (code != null && password != null && code.equals(CODE) && password.equals(PASSWORD)) {
			Admin admin = new Admin();
			admin.setCode(code);
			admin.setPassword(password);
			model.addAttribute("admin", admin);
			return new ModelAndView("redirect:/back/admin");
		} else {
			return new ModelAndView("/BackEnd/login");
		}
	}

}
